package com.itheima.service;

import com.itheima.common.R;
import com.itheima.mapper.DishMapper;
import com.itheima.mapper.FlavorsMapper;
import com.itheima.mapper.SetmealMapper;
import com.itheima.pojo.Dish;
import com.itheima.pojo.Flavors;
import com.itheima.pojo.Setmeal;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

/**
 * @author Envy
 */
@Service
public class SetmealService {
    @Resource
    private DishMapper dishMapper;
    @Resource
    private FlavorsMapper flavorsMapper;
    @Resource
    private SetmealMapper setmealMapper;

    /**
     * 菜品详情
     */
    public R<Dish> selectDetails() {
        //根据id查询菜品列表详情
        List<Dish> dishes = dishMapper.selectDetails();
        Dish dish = new Dish();
        //将查询到的菜品信息拷贝到dish对象中
        for (Dish dish1 : dishes) {
            BeanUtils.copyProperties(dish1, dish);
        }
        //查询口味列表详情
        List<Flavors> flavors = flavorsMapper.selectFlavorsDetails();
        //将查询到的数据放到dish对象中的flavors集合中
        dish.setFlavors(flavors);
        //此时的dish对象已经包含口味列表数据直接返回dish对象
        return R.success(dish);
    }

    /**
     * 套餐列表
     */
    public List<Setmeal> selectDetails(String categoryId, Integer status) {
        return setmealMapper.selectDetails(categoryId, status);
    }
}
